/*
 * IUnit.cpp
 *
 *  Created on: 07.12.2011
 *      Author: Kirill Blinov
 *      Copyright: LGPL
 */

#include "IUnit.h"

IUnit::IUnit( GAME_OBJECT* VisualisationInfo ) : physicParams(NULL)
{
	visualisationInfo = VisualisationInfo;

	//Move model position to coordinate center
	glm::mat4 TranslationMatrix = glm::translate( glm::mat4(1.0), ( VisualisationInfo->sphereCenter * glm::vec3(-1.0) ) );
	VisualisationInfo->worldMatrix *= TranslationMatrix;
}

IUnit::IUnit( const IUnit& Base ) : physicParams(NULL)
{
	visualisationInfo = new GAME_OBJECT( *Base.visualisationInfo );
}

IUnit::~IUnit()
{
	if ( physicParams != NULL )
	{
		delete physicParams;
	}

	delete visualisationInfo; //It should be always allocated
}

/*
 * Returns true on the first call only, so the name can be changed only set once.
 */
bool
IUnit::SetName( const std::string Name )
{
	bool Result = !name.empty();

	if ( Result )
	{
		name = Name;
	}

	return Result;
}

/*
 * Sets initial object parameters like a speed, axeleration e.t.c.
 * Returns true on the first call only.
 */
bool
IUnit::SetPhysicParams( const UNIT_PHYSIC_PARAMS &PhysicParams )
{
	return visualisationInfo->UpdatePhysicParams( PhysicParams );
}

const std::string
IUnit::GetName() const
{
	return name;
}

UINT_EVENT
IUnit::PopEvent()
{
	UINT_EVENT Event = eventQueue.front();
	eventQueue.pop();
	return Event;
}

